home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / graphic import.export / start code / alphacompositing.c next >
Encoding:
Text File  |  2000-10-06  |  2.9 KB  |  93 lines

  1. // Graphics Importer and Exporter Samples
  2. // This example takes two images and composites them together
  3. // demonstrating the use of different graphic modes
  4. // Originally written by Sam Bushell for QuickTime "Live" '99
  5. // WWDC 2000 Introduction to QuickTime
  6.  
  7. #include "MacShell.h"
  8.  
  9. void AlphaComposite( void )
  10. {
  11.     OSErr err = noErr;
  12.     Handle hOpenTypeList = NewHandle(0);
  13.     long  numTypes = 0;
  14.     FSSpec    theFSSpec;
  15.     GraphicsImportComponent backgroundImporter = 0, foregroundImporter = 0;
  16.     Rect backgroundBounds, windowBounds, foregroundBounds;
  17.     WindowPtr window = NULL;
  18.     MatrixRecord matrix;
  19.     RGBColor whiteColor;
  20.     FixedPoint backgroundCenter;
  21.  
  22.     BuildGraphicsImporterValidFileTypes( hOpenTypeList, &numTypes );
  23.     HLock( hOpenTypeList );
  24.     
  25.     // prompt for a background image.
  26.     err = GetOneFileWithPreview(numTypes, (OSTypePtr)*hOpenTypeList, &theFSSpec, NULL);
  27.     if (err) goto bail;
  28.     err = GetGraphicsImporterForFile( &theFSSpec, &backgroundImporter );
  29.  
  30.     // prompt for a foreground image.
  31.     err = GetOneFileWithPreview(numTypes, (OSTypePtr)*hOpenTypeList, &theFSSpec, NULL);
  32.     if (err) goto bail;
  33.     err = GetGraphicsImporterForFile( &theFSSpec, &foregroundImporter );
  34.     err = GraphicsImportGetNaturalBounds( backgroundImporter, &backgroundBounds );
  35.     
  36.     windowBounds = backgroundBounds;
  37.     OffsetRect( &windowBounds, 10, 45 );
  38.     window = NewCWindow( NULL, &windowBounds, "\pAlpha Composite", true, documentProc, (WindowPtr)-1, true, 0);
  39.     
  40. // Step 1. Insert DrawBackground.clp here...
  41.  
  42.     
  43.     pause();
  44.     
  45.     // center the foreground image over the background image
  46.     // get the native size of the foreground image
  47.     // offset the image to center it
  48.     // set the rectangle in which to draw an image
  49. // Step 2. Insert CenterForeground.clp here...
  50.     
  51.     // draw the foreground image over the background image,
  52.     // using the default graphics mode, ditherCopy.
  53.     err = GraphicsImportSetGWorld( foregroundImporter, GetWindowPort( window ), NULL );
  54.     err = GraphicsImportDraw( foregroundImporter );
  55.  
  56.     pause();
  57.     
  58.     // redraw the background.
  59.     err = GraphicsImportDraw( backgroundImporter );
  60.     
  61.     // draw the foreground using the transparent graphics mode, with white transparent.
  62.     whiteColor.red = 0xffff;
  63.     whiteColor.green = 0xffff;
  64.     whiteColor.blue = 0xffff;
  65. // Step 3. Insert SetGraphicsMode.clp here...
  66.  
  67.     err = GraphicsImportDraw( foregroundImporter );
  68.  
  69.     pause();
  70.     
  71.     // redraw the background.
  72.     err = GraphicsImportDraw( backgroundImporter );
  73.     
  74.     // draw the foreground using the straight alpha graphics mode.
  75. // Step 4. Insert SetGraphicsModeAlpha.clp here...
  76.  
  77.     err = GraphicsImportDraw( foregroundImporter );
  78.  
  79.     pause();
  80.     
  81.     // redraw the background.
  82.     err = GraphicsImportDraw( backgroundImporter );
  83.     
  84.     // draw the foreground *rotated 30 degrees*, using the straight alpha graphics mode.
  85. // Step 5. Insert Rotate.clp here...
  86.  
  87.  
  88. bail:
  89.     if ( backgroundImporter ) CloseComponent( backgroundImporter );
  90.     if ( foregroundImporter ) CloseComponent( foregroundImporter );
  91.     if ( hOpenTypeList)    DisposeHandle( hOpenTypeList );
  92. }
  93.